var SetHalfMaterialname = function () {
  var template = /*html*/ `
    <div class="material-config-setting">
      <div style="margin-bottom:10px">
        <el-button type="primary" @click="toAddMaterial(true)">添加半成品类型</el-button>
      </div>
      <div class="material-config-table-div">
        <el-table fit stripe border ref="feedOrderTable" :data="halfMaterialNameList" style="width:100%;" height="parent">
          <el-table-column prop="halfMaterialName" label="半架组合名称" min-width="120px" header-align="center"></el-table-column>
          <el-table-column label="状态" min-width="80px" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.status==1">使用</span>
              <span v-if="scope.row.status==2">禁用</span>
            </template>
          </el-table-column>
          <el-table-column prop="createUser" label="创建人" min-width="100px" header-align="center"></el-table-column>
          <el-table-column :resizable="false" prop="createTime" label="创建时间" width="100px" align="center"></el-table-column>
          <el-table-column :resizable="false" label="操作" width="80px" align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="updateDialog(scope.row)">修改</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div style="margin-top:5px;text-align:right" v-if="pagination.totalCount!==0">
        <el-pagination background :page-size="pagination.pageSize" :total="pagination.totalCount" :current-page.sync="pagination.currentPage"
          @current-change="pageChange"></el-pagination>
      </div>

      <!-- 修改弹出框 -->
      <el-dialog title="修改物料属性" :visible.sync="updateDialogVisible">
        <el-form label-width="auto">
          <el-form-item label="半成品名称">
            <el-input v-model="updateParam.halfMaterialName"></el-input>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="updateParam.status" placeholder="请选择状态">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="updateDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="updateHalfMaterialName">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog title="添加物料属性" :visible.sync="addDialogVisible">
        <el-form label-width="auto">
          <el-form-item label="半成品名称">
            <el-input v-model="halfMaterialName" style='width:200px;'></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="addDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="addCompanyHalfMaterial()">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  `;

  return {
    data: function () {
      var search = {
        halfMaterialNameSearch: '',
        statusSearch: ''
      };
      return {
        loading: false,
        updateDialogVisible: false,
        addDialogVisible: false,
        halfMaterialNameList: [],
        search: _.cloneDeep(search),
        oldSearch: _.cloneDeep(search),
        materialTypeArray: [],
        pagination: {
          currentPage: 1,
          totalCount: 0,
          pageSize: 15
        },
        updateParam: {},
        halfMaterialName: ''
      };
    },
    created: function () {
      var self = this;
      this.loading = true;
      SysUtil.getUser().then(function (user) {
        self.loading = false;
        self.getCompanyHalfMaterialName(true);
      })
    },
    methods: {
      toAddMaterial:function(){
        this.addDialogVisible = true;
      },
      addCompanyHalfMaterial: function () {
        var self = this;
        if (self.halfMaterialName == '') {
          self.$alert('请输入半成品名称', '提示', {});
          return false;
        }
        this.loading = true;
        ajaxRequest("structureTree/addCompanyHalfMaterial", {
          halfMaterialName: self.halfMaterialName
        }, true).then(function (res) {
          self.loading = false;
          self.$alert(res, '信息', {
            callback: function () {
              self.getCompanyHalfMaterialName();
            }
          });
        }).catch(function () {
          self.loading = false;
        });
        self.addDialogVisible = false;
      },
      updateHalfMaterialName: function () {
        var self = this;
        var postData = self.updateParam;
        if (postData.halfMaterialName == '') {
          self.$alert('请输入半成品名称', '提示', {});
          return false;
        }
        this.loading = true;
        ajaxRequest("structureTree/updateHalfMaterialName", postData, true).then(function (res) {
          self.loading = false;
          self.updateDialogVisible = false;
          self.$alert(res, '信息', {
            callback: function () {
              self.getCompanyHalfMaterialName(false);
            }
          });
        }).catch(function () {
          self.loading = false;
        });
      },
      updateDialog: function (row) {
        this.updateDialogVisible = true;
        this.updateParam = _.cloneDeep(row);
      },
      getCompanyHalfMaterialName: function (isSearch) {
        if (!isSearch) {
          this.search = _.cloneDeep(this.oldSearch);
        }

        var pagination = this.pagination;
        var pageSize = pagination.pageSize;
        var start = (pagination.currentPage - 1) * pageSize;
        var search = this.search;
        search.start = start;
        search.length = pageSize;
        var self = this;
        this.loading = true;
        ajaxRequest("structureTree/getCompanyHalfMaterialName", search, true).then(function (res) {
          self.halfMaterialNameList = res.returnData;
          self.pagination.totalCount = res.iTotalRecords;
          self.loading = false;
        }).catch(function () {
          self.loading = false;
        });
      },
      pageChange: function () {
        this.getCompanyHalfMaterialName(false);
      }
    },
    template: template

  };
}();
